﻿@model MvcCmsProjectTracker.ViewModels.ProjectCustomFieldViewModel
<div id="customfields">
    @if (Model.CustomFields.Count > 0)
    { 
        <table id="category-table">
            <tr>
                <th>
                </th>
                <th>
                    Field Name
                </th>
                <th>
                    Type
                </th>
                <th>
                    Required
                </th>
            </tr>
            @foreach (var item in Model.CustomFields)
            { <tr id="#row-@item.CustomFieldID ">
               <td>
                   @Ajax.ActionLink("Delete", "DeleteCustomField", new { id = item.CustomFieldID }, new AjaxOptions { HttpMethod="POST", UpdateTargetId = "customfields", OnFailure = "handleFailure", OnSuccess = "StyleControls", Confirm = "Are you sure you want to delete this custom field?" })
               </td>
               <td>
                   @item.Name
               </td>
               <td>
                   @switch (item.DataType)
                   {
                       case 0:
                           Response.Write("String");
                           break;
                       case 1:
                           Response.Write("Integer");
                           break;
                       case 2:
                           Response.Write("Decimal");
                           break;
                       case 3:
                           Response.Write("Date");
                           break;
                       default:
                           Response.Write("Undefined");
                           break;
                   }
               </td>
               <td>
                   @using (Ajax.BeginForm("EditCustomField", "Project", new { id = item.CustomFieldID }, new AjaxOptions { HttpMethod="POST", UpdateTargetId = "customfields", OnSuccess = "StyleControls", OnFailure = "handleFailure" }))
                   {
                       if (item.Required)
                       {
                           Response.Write(@"<input type=""checkbox"" name=""required"" checked=""checked"" value=""true"" /> ");
                       }
                       else
                       {
                           Response.Write(@"<input type=""checkbox"" name=""required"" value=""true"" /> ");
                       }
                       <input type="submit" value="Save" />
                   }
               </td>
           </tr>
            }
        </table>
    }
    @using (Ajax.BeginForm("AddCustomField", "Project", new { id = Model.ProjectID }, new AjaxOptions { HttpMethod="POST", UpdateTargetId = "customfields", OnSuccess = "StyleControls", OnFailure = "handleFailure" }))
    { 
        <label for="name">
            Field Name:</label>
        @Html.TextBox("fieldname", "")
        @Html.DropDownList("datatype", Model.CustomFieldDataTypes) 
        <input type="checkbox" name="required" value="true" /><text>Required</text>
        <input type="submit" value="Submit" />
    }
    @Html.Partial("ControlsProjectTracker/Message", Model);
</div>
<script type="text/javascript">
    $(function () {
        $("input:submit, button").button();
    });
</script>
